package org.batatasframework.chart.columns;

import java.text.Format;

import org.batatasframework.chart.ChartCell;

public abstract class AbstractFormatableColumn<T> extends AbstractValueColumn<T>{

	/** 如果有指定的话，可以对显示的结果进行格式化处理 */
	protected Format format;
	
	protected AbstractFormatableColumn(String name) {
		super(name);
	}

	public void setFormat(Format format) {
		this.format = format;
	}
	
	@Override
	protected ChartCell createCell() {
		return new FormatableChartCell();
	}
	
	protected class FormatableChartCell extends InternalChartCell{
		
		@Override
		public String toString() {
			Object value = getValue();
			if(null == value) return nullValue;
			if(null == format) return value.toString();
			return format.format(format);
		}
	}
	
}
